<?php

require 'common.php';

$projects = ReadProjectFromDir("xml");
$projectname = ReadProjectNamesFromDir("xml/archive");

for($i=0;$i< count($projectname);$i++)
{

//    echo $projectname[$i];
}
//$projects = ReadProjectData();
usort($projects, "CompareProjects");
SaveProjectsXML($projects);
SaveLastWeekProjectsXML($projects);
SavePieChartLastWeekProjects($projects);
SavePieChartAllProjects($projects);
SaveLineChartProjects($projects);


foreach ($engineer_tags as $key => $value)    
{
    SaveProjectsEngineer($projects,$key);
    SavePieChartEngineer($projects,$key);
}
?>



<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>UI and Graphics Team Dashboard</title>
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="easyui/demo/demo.css">
	<script type="text/javascript" src="easyui/jquery.min.js"></script>
	<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>
    <link type="text/css" rel="Stylesheet" href="themes/vader/jquery-ui.css">
</head>

<script type="text/javascript">
    $(document).ready(function () {

        

        $('.links').click(function(){

            var graph_image = document.getElementById("graph-image");
            graph_image.src = "generated/"+$(this).attr("title")+".png";
            
            var graph_pop = document.getElementById("pop");
            
            console.log(graph_pop);
            graph_pop.href="showgantt.php?id=generated/"+$(this).attr("title")+".xml&multiple";
            graph_pop.title=$(this).attr("name");

            
            
        })

        $('a#pop').live('click', function (e) {
            e.preventDefault();
            var page = $(this).attr("href")
            var pagetitle = $(this).attr("title")
            var $dialog = $('<div></div>')
            .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
            .dialog({
                autoOpen: false,
                modal: true,
                height: 400,
                width: 1200,
                title: pagetitle
            });
            $dialog.dialog('open');
        });
    });
</script>


<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF" background="img/circuit.jpg">

	<div class="easyui-panel" title="Projects" style="width:100%;height:100%;padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			

			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'west',split:true" style="width:100%;height:900px;padding:10px">
                    
					<div class="easyui-accordion" style="width:50%;">
                        <div id="graphs" title="Graphs"  style="padding:10px;">   
                                <a href="#" title="last-projects" class="links">Last Week</a>
<?php
                                foreach ($engineer_tags as $key => $value)    
                                {
                                    echo '<a href="#" title="'.$key.'" name="'.$value.'" class="links">'.$value.'</a>';                                
                                    echo '&nbsp';
                                }
?>    
                                <br><br>
                                <img id="graph-image" alt="Pie chart"  src="generated/last-projects.png"/>
                                <br>
                                <a id="pop"  style="text-align:right;" title="Last Week Tasks" href="showgantt.php?id=generated/last-projects.xml&multiple">Gantt</a>
                        </div>        
                        
<?php
                        
                        echo '<div id="graphs" title="Current Projects (Last week updates)"  style="padding:10px;">';
                        echo '<div class="easyui-accordion" style="width:100%;">';
						foreach ($projects as $project)
						{
    						if($project->recent != true)
        						break;


                            echo '<div title="'.$project->name.'" style="padding:10px;">';	
	                        echo '<a id="pop" style="text-align:right;" title="'.$project->name.'" href="'.'showgantt.php?id='.basename($project->link, ".xml").'">Project Gantt</a>';
                            foreach ($project->subprojects as $subproject)
    						{
                                if($subproject->recent != true )
                                    continue;

                                if($subproject->show == true)
                                    echo '<h3 style="color:#ffaa00;"> Sub Project   --- '.$subproject->name.'</h3>';

                                foreach ($subproject->milestones as $milestone)
                                {   
                                    if($milestone->recent != true)
                                        continue;
                                    echo '<h3 style="color:#0099FF;">'.$milestone->name.'</h3>';
                                    foreach ($milestone->logs as $log)
            						{
                						if($log->recent)
                						{
                							echo '</p>';
                    						echo $log->msg; 
                    						echo '</p>';
                						}
            						}
                       			}
           					}  
                            echo '</div>';
        				}
                        echo '</div>';
                        echo '</div>';


                        echo '<div title="'."Old Projects".'"  style="padding:10px;">';   

                        foreach ($projects as $project)
                        {
                            if($project->recent == true)
                                continue;

                            echo '<div title="'.$project->name.'"  style="padding:10px;">'; 
                            echo '<a id="pop" style="text-align:right;" title="'.$project->name.'" href="'.'showgantt.php?id='.basename($project->link, ".xml").'">'. $project->name .'</a>';
                            echo '</div>';
                        }
                        if(count($projectname)>0)
                        {
                            echo '</div>';   
                            echo '<div title="'."Archived Projects".'"  style="padding:10px;">';   
                            for($i=0;$i< count($projectname);$i++)
                            {
                                echo '<div title="'.$project->name.'"  style="padding:10px;">'; 
                                $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($projectname[$i]));
                                echo '<a id="pop" style="text-align:right;" title="'.$projectname[$i].'" href="'.'showgantt.php?id='.$projectname[$i].'">'. $withoutExt .'</a>';
                                echo '</div>';
                            }
                            echo '</div>';   
                        }    
?>              
					</div>
				</div>
			</div>


			<div data-options="region:'east'" style="width:50%;padding:10px">
                <a id="pop" style="text-align:right;" title="All Projects" href="showgantt.php?id=generated/projects.xml&multiple">Panel View</a>
                <img id="graph-image" alt="Pie chart"  src="generated/workload.png" />
                <iframe id="foo" name="foo" width="100%" height="100%" src="showgantt.php?id=generated/projects.xml&multiple"></iframe>;
			</div>
		</div>
	</div>
</body>
</html>
